package example.collections;

import java.util.HashSet;
import java.util.Iterator;

/**
 * Created by lenovo on 2016/11/7 0007.
 * Collection 类的 collection.remove() 方法来删除集合中的指定的元素
 */
public class Remove {
    public static void main(String[] args) {
        int size;
        HashSet<String> hashSet = new HashSet<String>();
        String str1 = "Yellow", str2 = "White", str3 =
                "Green", str4 = "Blue";
        Iterator<String> iterator;
        hashSet.add(str1);
        hashSet.add(str2);
        hashSet.add(str3);
        hashSet.add(str4);
        System.out.print("集合数据: ");
        iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
        hashSet.remove(str2);
        System.out.println("删除之后 [" + str2 + "]\n");
        System.out.print("现在集合的数据是: ");
        iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
        size = hashSet.size();
        System.out.println("集合大小: " + size + "\n");
    }
}
